import { DataTypes, Model } from 'sequelize'
import { sequelize } from './index'

export class GameBet extends Model {
  public id!: number
  public gameId!: string
  public userId!: number
  public amount!: number
  public target!: string
  public result?: string
  public winAmount?: number
  public status!: string
}

GameBet.init(
  {
    id: {
      type: DataTypes.INTEGER,
      autoIncrement: true,
      primaryKey: true,
    },
    gameId: {
      type: DataTypes.STRING(32),
      allowNull: false,
    },
    userId: {
      type: DataTypes.INTEGER,
      allowNull: false,
    },
    amount: {
      type: DataTypes.DECIMAL(10, 2),
      allowNull: false,
    },
    target: {
      type: DataTypes.STRING(20),
      allowNull: false,
    },
    result: {
      type: DataTypes.STRING(20),
    },
    winAmount: {
      type: DataTypes.DECIMAL(10, 2),
    },
    status: {
      type: DataTypes.ENUM('pending', 'settled', 'cancelled'),
      defaultValue: 'pending',
    },
  },
  {
    sequelize,
    tableName: 'game_bets',
    indexes: [
      {
        fields: ['gameId'],
      },
      {
        fields: ['userId'],
      },
      {
        fields: ['createdAt'],
      },
    ],
  }
)
